<?php

class NoteList{
	var $notes ;
	function NoteList($array){
		$this->notes = $array ;
	}
	
	function Filter($type, $param){
		$result = array() ;
		//echo "Filter ".$type."=".$param ;
		foreach($this->notes as $note){
			if( $type == "simulation" and ( $param or $note["note"]!=-1)) {
				array_push($result,$note);
				}
			elseif( $type == "dateBefore" and $note["date"]<$param ) array_push($result,$note);
			elseif( $type == "dateAfter" and $note["date"]>$param ) array_push($result,$note);
			elseif( $type == "matiere" and $note["matiere"]==$param ) array_push($result,$note);
			elseif( $type == "matiereList" and in_array($note["matiere"],$param) ) array_push($result,$note);
		}
		return new NoteList($result) ;
		}
	
	function Moyenne(){
		$points = 0;
		$coeffs = 0;
		foreach($this->notes as $note){
			if( $note["note"] != -1 ) $points += $note["note"] * $note["coefficient"] ;
			else $points += $note["simulation"] * $note["coefficient"] ;
			
			$coeffs += $note["coefficient"];
		}
		if( $coeffs != 0 ) return new Note( array($points/$coeffs,$coeffs) );
		else return new Note(array(-1,-1),false) ;
	}
	
	function SommeCoefs(){
		$result = 0;
		foreach($this->notes as $note){
			$result += $note["coefficient"];
		}
		return $result ;
	}
}

?>